﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace MathService
{
    internal abstract class TypeConverter<T> : ExpandableObjectConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type t)
        {
            return t == typeof(string) || base.CanConvertFrom(context, t);
        }

        public override object ConvertTo(ITypeDescriptorContext Context, CultureInfo Culture, object Value, Type DestType)
        {
            return DestType == typeof(string) && Value is T
                       ? Value.ToString()
                       : base.ConvertTo(Context, Culture, Value, DestType);
        }
    }
}